package com.liuheng.spzx.user.service.impl;

import com.liuheng.spzx.user.service.EmailService;
import com.liuheng.spzx.user.utils.EmailUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class EmailServiceImpl implements EmailService {
    //发送邮箱配置类
    @Autowired
    private JavaMailSender javaMailSender;
    @Autowired
    private RedisTemplate redisTemplate;
    @Override
    public String sendValidateCode(String phone) {
        String s = EmailUtil.sendMail(javaMailSender, phone);
        redisTemplate.opsForValue().set(phone, s, 10, TimeUnit.MINUTES);
        return s;
    }
}
